#include "inputdlg.h"
#include <QLayout>
#include <QInputDialog>

InputDlg::InputDlg(QWidget* parent):QDialog(parent)
{
    setWindowTitle(tr("stabard input dialog"));
    nameLabel1=new QLabel;
    nameLabel1->setText(tr("name"));
    nameLabel2=new QLabel;
    nameLabel2->setText(tr("james"));
    nameLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
    sexLabel1=new QLabel;
    sexLabel1->setText(tr("sex:"));
    sexLabel2=new QLabel;
    sexLabel2->setText(tr("man"));
    ageLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
    ageLabel1=new QLabel;
    ageLabel1->setText(tr("Age:"));
    ageLabel2=new QLabel;
    ageLabel2->setText(tr("37"));
    ageLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
    scoreLabel1=new QLabel;
    scoreLabel1->setText(tr("score"));
    scoreLabel2=new QLabel;
    scoreLabel2->setText(tr("socre:"));
    scoreLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken);
    nameBtn=new QPushButton;
    nameBtn->setText(tr("changename"));
    sexBtn=new QPushButton;
    sexBtn->setText(tr("chgangesex"));
    ageBtn=new QPushButton;
    ageBtn->setText(tr("changeage"));
    scoreBtn=new QPushButton;
    scoreBtn->setText(tr("changescore"));

    QGridLayout *mainlayout=new QGridLayout(this);
    mainlayout->setMargin(15);
    mainlayout->setSpacing(10);
    mainlayout->addWidget(nameLabel1,0,0);
    mainlayout->addWidget(nameLabel2,0,1);
    mainlayout->addWidget(nameBtn,0,2);
    mainlayout->addWidget(sexLabel1,1,0);
    mainlayout->addWidget(sexLabel2,1,1);
    mainlayout->addWidget(sexBtn,1,2);
    mainlayout->addWidget(ageLabel1,2,0);
    mainlayout->addWidget(ageLabel2,2,1);
    mainlayout->addWidget(ageBtn,2,2);
    mainlayout->addWidget(scoreLabel1,3,0);
    mainlayout->addWidget(scoreLabel2,3,1);
    mainlayout->addWidget(scoreBtn,3,2);

    connect(nameBtn,SIGNAL(clicked(bool)),this,SLOT(ChangeName()));
    connect(sexBtn,SIGNAL(clicked(bool)),this,SLOT(ChangeSex()));
    connect(ageBtn,SIGNAL(clicked(bool)),this,SLOT(ChangeAge()));
    connect(scoreBtn,SIGNAL(clicked(bool)),this,SLOT(ChangeScore()));

  }

void InputDlg::ChangeName()
{
    bool ok;
    QString text=QInputDialog::getText(this,tr("Standard string input window "),
                                       tr("input name: "),QLineEdit::Normal,
                                       nameLabel2->text(),&ok);
    if(ok&&!text.isEmpty())
    {
        nameLabel2->setText(text);
    }
}

void InputDlg::ChangeSex()
{
    QStringList sexItems;
    sexItems<<tr("man")<<tr("woman");
    bool ok;
    QString sexItem=QInputDialog::getItem(this,tr("strandard items selected window"),
                                          tr("chose the sex:"),sexItems,0,false,&ok);
    if(ok&&sexItem.isEmpty())
    {
        sexLabel2->setText(sexItem);
    }
}
void InputDlg::ChangeAge()
{
    bool ok;
    int age=QInputDialog::getInt(this,tr("standard int input"),tr("input age"),
                                 ageLabel2->text().toInt(&ok),0,100,1,&ok);
    if(ok)
        ageLabel2->setText(QString(tr("%1")).arg(age));
}

void InputDlg::ChangeScore()
{

}







